﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using UWP.Douban.Models;
using Windows.UI.Xaml.Navigation;

namespace UWP.Douban.Mvvm
{
    public class GroupTopicVm:BaseVm
    {
        private Group _group;
        private bool _groupDescriptionCollapsed = false;

        public GroupTopicVm()
        {
            Topics = new ObservableCollection<Topic>();

            ShowGroupDescriptionCommand = new RelayCommand<object>(ShowGroupDescription);
        }

        private void ShowGroupDescription(object obj)
        {
            GroupDescriptionCollapsed = !GroupDescriptionCollapsed;
        }

        public Group Group
        {
            get { return _group; }
            set
            {
                if (_group == value) return;
                _group = value;
                OnPropertyChanged();
            }
        }


        public bool GroupDescriptionCollapsed
        {
            get { return _groupDescriptionCollapsed; }
            set
            {

                if (_groupDescriptionCollapsed == value) return;
                _groupDescriptionCollapsed = value;
                OnPropertyChanged();
            }
        }


        public ObservableCollection<Topic> Topics { get; set; }

        public ICommand ShowGroupDescriptionCommand { get; private set; }



        public override async void OnNavigatedTo(NavigationEventArgs e)
        {
            Group = await SampleData.SampleDataUtil.GetGroupDetail();


            var topics = await SampleData.SampleDataUtil.GetGroupTopics();

            foreach (var topic in topics)
            {
                Topics.Add(topic);
            }
            base.OnNavigatedTo(e);
        }
    }
}
